const openid = getApp().globalData.openid;

Page({
    data: {
        //轮播图，从云服务器端获取
        swiperList: [],
    },

    onLoad: function (options) {
        //获取轮播图
        let swiper = wx.getStorageSync('swiper');
        if (!swiper || Date.now() - swiper.time > 1000 * 60 * 30) {
            this.getSwiperList();
        } else {
            this.setData({
                swiperList: swiper.data
            })
        }
    },

    getSwiperList() {
        wx.cloud.database().collection("banners").get()
            .then(res => {
                this.setData({
                    swiperList: res.data
                });
                wx.setStorageSync('swiper', {
                    time: Date.now(),
                    data: res.data
                });
            })
            .catch(err => {
                console.log("请求失败", err);
            });
    },
 
    clearStorage() {
        wx.clearStorage({
          success: (res) => {
              wx.showToast({
                title: '成功清除本地缓存',
              })
          },
        })
    }
    
})